package ae.pcfc.etks.online.itworx.ehs.web.facade.impl;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import ae.pcfc.etks.online.itworx.ehs.web.entity.DocumentType;
import ae.pcfc.etks.online.itworx.ehs.web.entity.OFCDocument;
import ae.pcfc.etks.online.itworx.ehs.web.enums.RequestStatus;
import ae.pcfc.etks.online.itworx.ehs.web.exception.DocumentTypeAlraedyExistException;
import ae.pcfc.etks.online.itworx.ehs.web.exception.DocumentTypeNotFoundException;
import ae.pcfc.etks.online.itworx.ehs.web.exception.InvalidDocumentTypeNameException;
import ae.pcfc.etks.online.itworx.ehs.web.exception.InvalidInputException;
import ae.pcfc.etks.online.itworx.ehs.web.facade.EHSFacade;
import ae.pcfc.etks.online.itworx.ehs.web.manager.EHSManager;

public class EHSFacadeImpl extends BaseFacade implements EHSFacade {

	private EHSManager ehsManager;

	public EHSManager getEhsManager() {
		return ehsManager;
	}

	public void setEhsManager(EHSManager ehsManager) {
		this.ehsManager = ehsManager;
	}

    @Transactional
	public List<DocumentType> getAllDocumentType() {
		return ehsManager.getAlldocumentType();
	}


	public void createNewDocumentType(DocumentType documentType) throws DocumentTypeAlraedyExistException, InvalidDocumentTypeNameException, InvalidInputException {
		if (documentType != null) {
			ehsManager.createNewDocumentType(documentType);
		}

	}
	
	@Override
	public DocumentType getDocumentTypeById(Long id) throws DocumentTypeNotFoundException, InvalidInputException {
		return ehsManager.getDocumentTypeById(id);
	}
	
	public void deleteDocumentType(Long id) throws DocumentTypeNotFoundException, InvalidInputException {
		if (id > 0) {
			ehsManager.deleteDocumentType(id);
		}

	}


	public void updateDocumentType(DocumentType documentType) throws DocumentTypeNotFoundException, InvalidInputException, InvalidDocumentTypeNameException, DocumentTypeAlraedyExistException {
		if (documentType != null) {
			ehsManager.updateDocumentType(documentType);
		}

	}


//	public DocumentType retrieveDocumentTypeByName(String name,Long id) {
//		DocumentType documentType = null;
//		if (ServiceValidator.validateDocumentTypeTitle(name)) {
//			documentType = ehsManager.retrieveDocumentTypeByName(name,id);
//		}
//		return documentType;
//	}

	@Override
	public OFCDocument findOFCDocumentById(long id)
			throws InvalidInputException {
		return ehsManager.findOFCDocumentById(id);
	}
	
	@Override
	public List<DocumentType> getAllDocumentTypeByOFCStatus(
			String documentName, RequestStatus requestStatus) {
		return ehsManager.getAllDocumentTypeByOFCStatus(documentName, requestStatus);
	}

}
